﻿using UnityEngine;
using System.Collections;
/// <summary>
/// 背景控制
/// </summary>
public class BGCtrl : MonoBehaviour
{
    public GameObject bg;
    public float speed = 1;
    public static BGCtrl Inst;
    // Use this for initialization
    void Start()
    {
        bg1 = bg;
        bg2 = (GameObject)Instantiate(bg, transform.position, transform.rotation);
        move();
        Inst = this;
    }
    Vector3 t;
    void move()
    {
        t = bg1.transform.position;
        t.x  += 6.71156117f;
        bg2.transform.position = t;
    }
    // Update is called once per frame
    void Update()
    {
        if(GameCtrl.gameState != GameState.dieing && GameCtrl.gameState != GameState.gameover)
        {
            bg1.transform.Translate(Vector3.left * speed * Time.deltaTime);
            move();

            if(bg1.transform.position.x <= -6.3f) //交换
            {
                GameObject g = bg1;
                bg1 = bg2;
                bg2 = g;
            }
        }
    }
    GameObject bg1, bg2;
}
